/*
 * @Author: yanyqf
 * @Date: 2020-03-10 14:08:22
 * @LastEditTime: 2020-04-25 22:28:04
 * @Description: file content
 */
import { vendorsGetTId } from 'utils/config.js';
import { orgCreateBusiness, onChange } from "./../common/index.js";
let tenantId;
let cookieStr = document.cookie.split(';').find(cur => cur.indexOf('tenantid=') != -1)
if (cookieStr) {
    tenantId = cookieStr.split('=')[1];
}

export function treemodalTpl () {
    let _this = this;
    return{
        items: [
            {    
                dataSource: 'personnelFiles_modalOrgTree_createEnter_area',
                itemtype: "tree",
                refPk: 'pkSrc',
                label: "组织",
                selectShowKey: 'sname',
                selectShowScode: 'scode',
                isMultiSelectedEnabled: false, 
                isCheckable: true,
                isCheckStrictly : true,
                isShowSearchArea : true,
                modalTitle :'组织列表',
                reqRef: {
                    queryCondition: function () {

                        return { pkTenant: tenantId }
                    },
                    method: 'get',
                   refUrl: "/organization/getOrgByTenantId",
                 // refUrl: "/organization/getPermOrgByUser",
                
                },
            },
            {    
                dataSource: 'personnelFiles_modalOrgTree_form_area',
                itemtype: "tree",
                refPk: 'pkSrc',
                label: "组织",
                selectShowKey: 'sname',
                selectShowScode: 'scode',
                isMultiSelectedEnabled: true, 
                isCheckable: true,
                isCheckStrictly : true,
                isShowSearchArea : true,
                modalTitle :'组织列表',
                reqRef: {
                    queryCondition: function () {

                        return { pkTenant: tenantId }
                    },
                    method: 'get',
                   refUrl: "/organization/getOrgByTenantId",
                 // refUrl: "/organization/getPermOrgByUser",
                
                },
            },
        
        ],
        events :{
            confirm:  function (selectList, source) {
                if(!_this.state.status){
                    selectList.item.length && orgCreateBusiness.call(_this, {pkOrg: selectList.item[0].pkSrc}, ()=>{
                        onChange.call(_this, {
                            checkedKeys: selectList.name,
                            checkedKeysId: selectList.id
                        })
                    })
                }else  if(_this.state.status&& _this.state.status !=="browse"){
                    onChange.call(_this, {
                        orgNames: selectList.name,
                        pkOrgs: selectList.id,
                        orgItems: selectList.item
                    })
                }
                
                console.log(selectList, "选中的数据")
            },
        }
    }
}